package StudyCode.summary.mycollection;

import java.util.*;

/**
 * 版权所有 科技与人文(www.tah1986.com)
 */
public class GetsMapContainingAllOfTheEntriesFromTheMapsProvided {
	static Map<String, String> union(final Map<String, String> map1,
	                                 final Map<String, String> map2) {
		final List<Map<String, String>> maps = new ArrayList<Map<String, String>>();
		maps.add(map1);
		maps.add(map2);
		return unionMaps(maps);
	}


	static Map<String, String> union(final Map<String, String> map1,
	                                 final Map<String, String> map2, final Map<String, String> map3) {
		final List<Map<String, String>> maps = new ArrayList<Map<String, String>>();
		maps.add(map1);
		maps.add(map2);
		maps.add(map3);
		return unionMaps(maps);
	}


	static Set<String> union(final Set<String> set1, final Set<String> set2) {
		final List<Set<String>> sets = new ArrayList<Set<String>>();
		sets.add(set1);
		sets.add(set2);
		return unionSets(sets);
	}


	private static Map<String, String> unionMaps(
			final List<Map<String, String>> maps) {
		final Map<String, String> union = new HashMap<String, String>();
		for (Map<String, String> map : maps) {
			union.putAll(map);
		}
		return union;
	}


	private static Set<String> unionSets(final List<Set<String>> sets) {
		final Set<String> union = new HashSet<String>();
		for (final Set<String> set : sets) {
			union.addAll(set);
		}
		return union;
	}
}
